package com.pcbly.web.components.views.jsp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Submit;

import com.opensymphony.xwork2.util.ValueStack;

public class ExtSubmit extends Submit {

	private String textAndIcon;
	public String getTextAndIcon() {
		return textAndIcon;
	}
	public void setTextAndIcon(String textAndIcon) {
		this.textAndIcon = textAndIcon;
	}
	public ExtSubmit(ValueStack stack, HttpServletRequest request,
			HttpServletResponse response) {
		super(stack, request, response);
		// TODO Auto-generated constructor stub
	}
	public void evaluateParams() {
		super.evaluateParams();
		if (textAndIcon == null) {
			textAndIcon = "";
		}
		if (textAndIcon.equals("text")) {
			textAndIcon = "-noicon ";
		} else if (textAndIcon.equals("icon")) {
			textAndIcon = "-icon ";
		} else {
			textAndIcon = "-text-icon ";
		}
		if(textAndIcon!=null){
			addParameter("textAndIcon", textAndIcon);
		}
		if (cssClass == null) {
			cssClass = "x-btn";
		}
		addParameter("cssClass", cssClass);
		if(onclick==null){
			onclick="";
		}
		StringBuilder sb=new StringBuilder();
		sb.append("this.className='");
		sb.append(cssClass);
		sb.append(" ");
		sb.append(cssClass);
		sb.append(textAndIcon);
		sb.append(" ");
		sb.append(cssClass);
		sb.append("-focus ");
		sb.append(cssClass);
		sb.append("-over ");
		sb.append(cssClass);
		sb.append("-click';");
		sb.append(onclick);
		
		addParameter("onclick", sb.toString());
		if(onmouseover==null){
			onmouseover="";
		}
		sb=new StringBuilder();
		sb.append("this.className='");
		sb.append(cssClass);
		sb.append(" ");
		sb.append(cssClass);
		sb.append(textAndIcon);
		sb.append(" ");
		sb.append(cssClass);
		sb.append("-over ");
		sb.append("';");
		sb.append(onmouseover);
		
		addParameter("onmouseover", sb.toString());
		
		if(onfocus==null){
			onfocus="";
		}
		
		sb=new StringBuilder();
		sb.append("this.className='");
		sb.append(cssClass);
		sb.append(" ");
		sb.append(cssClass);
		sb.append(textAndIcon);
		sb.append(" ");
		sb.append(cssClass);
		sb.append("-focus ");
		sb.append("';");
		sb.append(onfocus);
		
		if(onmouseout==null){
			onmouseout="";
		}
		
		sb=new StringBuilder();
		sb.append("this.className='");
		sb.append(cssClass);
		sb.append(" ");
		sb.append(cssClass);
		sb.append(textAndIcon);
		sb.append("';");
		sb.append(onmouseout);
		
		addParameter("onmouseout", sb.toString());
		
	}
}
